package com.cnsoft.portal.saas;

import javax.annotation.Resource;

import org.cnsoft.framework.beans.user.UserBean;
import org.cnsoft.framework.cache.session.SessionHelper;
import org.cnsoft.framework.support.MyPageControllerSupport;
import org.cnsoft.framework.utils.DateHelper;
import org.cnsoft.framework.utils.EmptyHelper;
import org.cnsoft.persistent.common.ManagerMenu.ManagerMenuDBO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cnsoft.persistent.company.C201010Partner.C201010PartnerDBO;
import com.cnsoft.persistent.company.C201010Partner.C201010PartnerDao;

/**
 * 过渡页面
 * 
 * @author ZmSoft
 * @version 0.1.0 2018/3/1
 * @since 0.1.0 2018/3/1
 */
@Controller
// @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@RequestMapping(value = "/pc/1.0/saas")
public class PageSaasHomeController extends MyPageControllerSupport {

	@Resource
	private C201010PartnerDao daoC201010Partner;

	// 首页-过度
	@RequestMapping(value = "/home.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView doHomePOST() throws Exception {
		ModelAndView modelAndView = getModelAndView("/saas/saas-main");

		// 查看用户认证情况
		C201010PartnerDBO partner = new C201010PartnerDBO();
		partner.setId(SessionHelper.currentCompanyId());
		super.showLog("Partner", SessionHelper.currentCompanyId());
		partner = daoC201010Partner.doRead(partner);

		super.showLog("Partner", partner);

		// 根据用户身份判断是否需要进入管理后台
		if (EmptyHelper.isEmpty(partner)) {
			// 第一次进来
			modelAndView = getModelAndView("/saas/saas-group");
		} else {
			modelAndView = getModelAndView("/saas/identity-ok");
			modelAndView.addObject("partner", partner);
		}

		// 基础信息
		UserBean currentUser = SessionHelper.currentUser();
		modelAndView.addObject("DDD", DateHelper.currentTimeMillis2());
		modelAndView.addObject("token", SessionHelper.currentToken());
		modelAndView.addObject("loginer", currentUser);

		return modelAndView; // 返回result对象给前端
	}

	// 管理后台首页
	@RequestMapping(value = "/main.do", method = RequestMethod.POST)
	public ModelAndView doMainPOST(ManagerMenuDBO param) throws Exception {
		ModelAndView modelAndView = getModelAndView("/saas/saas-main");
		// 基础信息
		UserBean currentUser = SessionHelper.currentUser();
		modelAndView.addObject("DDD", DateHelper.currentTimeMillis2());
		modelAndView.addObject("token", SessionHelper.currentToken());
		modelAndView.addObject("loginer", currentUser);

		return modelAndView; // 返回result对象给前端
	}

	// 身份保存
	@RequestMapping(value = "/identity.do", method = RequestMethod.POST)
	public ModelAndView doIdentityPOST(C201010PartnerDBO param) throws Exception {
		ModelAndView modelAndView = getModelAndView("/saas/identity-ok");

		// 保存用户资料
		super.showLog("Partner", param);
		param.setPartnerName("大展宏图");
		param.setId(SessionHelper.currentCompanyId());
		daoC201010Partner.doInsertOrUpdate(param);

		// 基础信息
		UserBean currentUser = SessionHelper.currentUser();
		modelAndView.addObject("DDD", DateHelper.currentTimeMillis2());
		modelAndView.addObject("token", SessionHelper.currentToken());
		modelAndView.addObject("loginer", currentUser);
		modelAndView.addObject("partner", param);

		return modelAndView; // 返回result对象给前端
	}

	// 身份认证
	@RequestMapping(value = "/identity-change.do", method = RequestMethod.POST)
	public ModelAndView doIdentityChangePOST() throws Exception {
		ModelAndView modelAndView = getModelAndView("/saas/saas-group");

		// 基础信息
		UserBean currentUser = SessionHelper.currentUser();
		modelAndView.addObject("DDD", DateHelper.currentTimeMillis2());
		modelAndView.addObject("token", SessionHelper.currentToken());
		modelAndView.addObject("loginer", currentUser);

		return modelAndView; // 返回result对象给前端
	}

	// 进入到业务后台
//	//SAAS模式拦截
//	{
//		String gameId = request.getParameter("gameId");
//		currentUser.setPassWord(gameId);//#MySAASBusinesslogicConfiger
//		super.doSaveUser(request, gameId, gameId, currentUser);
//	}

	
}
